// These styles apply on the sm-only breakpoint (i.e. on mobile), or when JavaScript is not enabled.
// This is because the mobile version is friendly to JS being disabled, and the desktop version is not very functional without JS.
@mixin sm-only-or-no-js {
    @include sm-only {
        @content;
    }
    @at-root html.js-disabled & {
        @content;
    }
}

.key-indicator-collection {
    $duration: 0.4s; // keep in sync with HEIGHT_ANIMATION_DURATION_IN_SECONDS in KeyIndicatorCollection.tsx

    --padding: var(--grid-gap, 24px);
    --border: #{$blue-20};

    margin: 24px 0;

    @include sm-only-or-no-js {
        margin: 8px -16px;
    }

    .accordion-item + .accordion-item {
        border-top: 1px solid var(--border);
    }

    .accordion-item .accordion-item__heading {
        margin: 0;
        @include sm-only-or-no-js {
            display: none;
        }
    }

    .accordion-item__button,
    .accordion-item__link-mobile {
        display: block;
        width: 100%;
        text-align: left;
    }

    .accordion-item__button {
        background-color: $blue-5;
        padding: 16px var(--padding);

        @include sm-only-or-no-js {
            padding-bottom: 0;
        }
    }

    // on desktop, show a clickable header that opens the accordion
    .accordion-item--closed .accordion-item__button {
        @include sm-only-or-no-js {
            display: none;
        }
    }

    // on mobile, show an anchor that links to the datapage
    .accordion-item__link-mobile {
        padding: 12px 0;
        line-height: 1.2;
        display: none;

        @include sm-only-or-no-js {
            display: block;
        }
    }

    .accordion-item--open .accordion-item__button {
        background-color: $blue-20;

        @include sm-only-or-no-js {
            background-color: $blue-5;
        }
    }

    .accordion-item--closed .accordion-item__button:hover {
        background-color: $blue-20;
    }

    .accordion-item__content {
        overflow: hidden;
        transition: height $duration cubic-bezier(0.76, 0, 0.24, 1);
    }

    .key-indicator-collection__header {
        margin-bottom: 16px;
        h2 {
            color: $blue-90;
            margin: 0;

            @include sm-only-or-no-js {
                font-size: 1.5rem;
                margin-bottom: 4px;
            }
        }

        p {
            color: $blue-60;
            margin: 0;
        }

        @include sm-only-or-no-js {
            padding: 16px 16px 0 16px;
            margin-bottom: 0;
        }
    }

    .key-indicator-collection__all-charts-button {
        // needed to align the button with the header
        margin-top: -16px;
        align-self: center;
        justify-self: end;

        @include sm-only-or-no-js {
            margin: 24px 16px;
            justify-self: unset;
            text-align: center;
            // below the accordion
            order: 1;
        }
    }

    .key-indicator-header {
        display: flex;
        justify-content: space-between;
        gap: 8px;
    }

    .key-indicator-header__left {
        display: flex;
        align-items: baseline;
    }

    .key-indicator-header__tab-icon {
        font-size: 0.8125rem;
        color: $blue-50;
        margin-right: 8px;
    }

    .key-indicator-header__title {
        @include body-2-semibold;
        color: $blue-90;
        margin-right: 8px;

        @include sm-only-or-no-js {
            line-height: 1.2;
        }
    }

    .accordion-item--closed .key-indicator-header__title {
        @include sm-only-or-no-js {
            margin-left: 0;
        }
    }

    .accordion-item__link-mobile:active:not(:hover)
        .key-indicator-header__title {
        text-decoration: underline;
        text-underline-offset: 4px;
    }

    .key-indicator-header__source {
        @include body-3-medium;
        display: inline-block;
        color: $blue-50;
    }

    .accordion-item--closed .key-indicator-header__source {
        @include sm-only-or-no-js {
            display: block;
            margin-top: 2px;
        }
    }

    .key-indicator-header__icon {
        color: $blue-90;
        font-size: 0.875rem;
        font-weight: 900;

        @include sm-only-or-no-js {
            font-size: 0.75rem;
        }
    }

    // hidden on mobile
    .key-indicator-header__icon[data-icon="plus"] {
        @include sm-only-or-no-js {
            display: none;
        }
    }

    // hidden on desktop
    .key-indicator-header__icon[data-icon="arrow-right"] {
        display: none;
        @include sm-only-or-no-js {
            display: inline-block;
        }
    }

    button[disabled] {
        cursor: default;
    }

    @include sm-only-or-no-js {
        --border: #{$blue-10};

        .accordion-item:first-of-type::after {
            content: "More featured indicators";
            @include h5-black-caps;
            display: block;
            margin: 24px var(--padding) 16px;
            color: $blue-60;
        }

        .accordion-item:nth-of-type(2) {
            border-top: 1px solid var(--border);
        }

        .accordion-item:last-of-type {
            border-bottom: 1px solid var(--border);
        }

        .accordion-item--closed {
            margin: 0 var(--padding);
        }
    }

    // overwrite <KeyIndicator /> styles
    .key-indicator {
        margin: 0;
        .indicator-metadata {
            display: none;
        }
    }
}
